﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class ServerListener
    {
        
        public delegate void ServerEventType(string besked);
        public event ServerEventType ServerEvent;

        private readonly Forbindelse _forbindelse;
        private bool _stop;



        public ServerListener(Forbindelse forbindelse)
        {
            _stop = false;
            this._forbindelse = forbindelse;
        }

        //lytter efter serveren
        public void Listen()
        {
           while (!_stop)
                if (ServerEvent != null)
                    ServerEvent(_forbindelse.StreamReader.ReadLine()+"\r\n");
        }

        public void Stop()
        {
            this._stop = true;
        }
    }
    
}
